package com.xiake.controller;

import com.xiake.pojo.User;
import com.xiake.service.UserService;
import com.xiake.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("login")
    //传入一个json数据需要
    public Result<User> login( @RequestBody User user){
      Result result=  userService.login(user);
        return result;
    }
    @GetMapping("getUserInfo")
    public Result<User> getUserInfo(@RequestHeader String token){
        Result result=userService.getUserInfo(token);
        return result;
    }
    @PostMapping("checkUserName")
    public Result<User> checkUserName(String username){
       Result result= userService.checkUsername(username);
       return result;
    }
    @PostMapping("regist")
    public Result<User> regist(@RequestBody User user){
        Result result=userService.register(user);
        return result;
    }

    @GetMapping("checkLogin")
    public Result<User> checkLogin(@RequestHeader String token){
        Result result=userService.checkLogin(token);
        return result;
    }
}
